<?php
/**
 * 产品 详情描述
 */


// 取得商品图片列表
foreach ($productInfo['img_pre'] AS $key => $val)
{
	// 中图
	$productInfo['img_pre'][$key]['m_img2'] = get_small_image($val['b_img'], $m_pic_format);
}

if (preg_match_all("/<img.*?src=\"(.*?)\".*?[\/]?\>/i",$productInfo['descript'],$imgs))
{
	$img = $imgs[1];

	if (is_array($img))
	{
		foreach ($img AS $key => $val)
		{
			// 去除部分图片width、height值(因接口返回width/height为比较大的数值)
			if (preg_match("/(width=[\"|\']([0-9]+)?[\"|\']|height=[\"|\']([0-9]+)?[\"|\'])/i", $imgs[0][$key] ))
			{
				$pic = preg_replace("/(width=[\"|\']([0-9]+)?[\"|\'])/i", 'width="320"', $imgs[0][$key]);
				$pic = preg_replace("/(height=[\"|\']([0-9]+)?[\"|\'])/i", '', $pic);
			}
			else
			{
				$pic = str_ireplace('/>', ' width="320" />', $imgs[0][$key]);
			}

			if (preg_match("/{pic:[1-3]}/", $val)){
				$number = substr($val, -2, 1);

				$pic = str_ireplace($val, $productInfo['img_pre'][$number-1]['m_img2'], $pic);
			}

			$productInfo['descript'] = str_replace($imgs[0][$key], $pic, $productInfo['descript']);
		}
	}
	else
	{
		$img2 = get_small_image($img, $pic_format);
		$productInfo['descript'] = str_replace($img, $img2, $productInfo['descript']);
	}
}
